package android.handler;

//import com.sun.xml.internal.ws.resources.HandlerMessages;

/**
 * @author Ajie
 * @date 2021-03-15
 * @function 模拟应用的主方法
 */
public class ActivityThread {

    public static void main(String[] args) {
        // 创建全局唯一主线程对象Looper对象
        Looper.prepare();

        Handler handler = new Handler(){
            @Override
            public void handlerMessage(Message msg) {
                super.handlerMessage(msg);
                System.out.println("res:"+msg.what+" "+msg.obj);
            }
        };


        // 模拟Handler发送事件
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message message = new Message();
                message.obj = "我最牛！打工人！干饭人！";
                message.what = 1;
                handler.sendMessage(message);
            }
        }).start();


        // 启动Looper循环获取消息
        Looper.loop();

    }

}
